package khh;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * If the robot is shot it turns red and if it shoots another robot it turns blue.
 * 
 * @author Kylan Hughes
 * @version 1.0
 */
public class TestKylanColorChange extends RobotTestBed {

  /** variables to test if the robot changes colors. */
  boolean red = false;
  boolean blue = false;
  /** testing variable returned values -16711936 for red and -65536 for blue. */
  int gunColor;
  
  /**
   * Specifies that SittingDuck and Kylan are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,khh.Kylan";
  }

  /**
   * This test runs for 10 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * At the end of each turn check if the color has changed if so then set flag.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    gunColor = robot.getGunColor();
    if (gunColor == -16711936) {
      // ARGB values for red are in bits 16-23
      red = true;
    }
    else if (gunColor == -65536) {
      // ARGB values for blue are in bits 0-7
      blue = true;
    }
  }

  /**
   * After the battle with crazy, see that it has been hit and has hit crazy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check red", red);
    assertTrue("Check blud", blue);
  }
}
